home *** CD-ROM | disk | FTP | other *** search
-
- #include "2BufRecordToBufCmd.h"
- #include "atob.h"
-
- #ifdef IRDEBUG
- #include "stdio.h"
- #endif
-
- #include "CD ROM.h"
- #include "PlayMovie.h"
- #include "KillApp.h"
- #include <Shutdown.h>
-
- struct IRStateStruct {
- long oldValue;
- short quitFlag;
- short CDPauseState; /* 0 = CD is paused, 1 = CD is playing */
- short CDPlayState;
- short CDScanState;
- ProcessSerialNumber IRProc;
- };
- typedef struct IRStateStruct IRStateStruct;
-
- void InitStuff(void);
- void MainEventLoop(void);
- void ProcessIR(IRStateStruct *IRState);
- void DoVideoIR(long theValue,IRStateStruct *IRState);
- void DoProcessIR(long theValue,IRStateStruct *IRState);
- void IRSwitchLayer(short forward, IRStateStruct *IRState);
- short IsMyWindow(WindowPtr theWindow);
- void OffsetWindow(WindowPtr theWindow, short h, short v);
- void InitAEStuff(void);
- void DoHighLevel(EventRecord *AERecord);
- pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
- pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
- pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
- pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
-
-
- extern WindowPtr myWindow[MAXWINDOWS];
- short quitFlag = 0;
-
-
- void
- main()
- {
-
- InitStuff();
-
- TestTheSystem (); // test the system to make sure the app will work
-
- InitAEStuff();
-
- InitPlayMovie();
-
- InitSoundStuff();
- StartRecord();
- #ifdef IRDEBUG
- printf("Start!\n");
- #endif
-
- MainEventLoop();
-
- SoundCleanUpAndQuit();
- ClosePlayMovie();
- }
-
- void
- InitStuff()
- {
- OSErr err;
-
- MoreMasters();
- MoreMasters();
- MoreMasters();
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- FlushEvents( everyEvent, 0 );
- MaxApplZone();
- InitCursor();
- }
-
- void
- ProcessIR(IRStateStruct *IRState)
- {
- long theValue;
- short sameVal;
-
- theValue = SendSoundData();
-
- if (theValue == IRState->oldValue) {
- theValue = 0;
- }
- else {
- IRState->oldValue = theValue;
- if (IRState->CDScanState == 1) {
- APause(0, GetDrvRefNum(-2));
- IRState->CDScanState = 0;
- IRState->CDPauseState = 1;
- }
- }
-
- if (theValue > 0) {
- #ifdef IRDEBUG
- printf("Value: %ld\n", theValue);
- #endif
-
-
- if (theValue == 2232) {
- AStop(0,GetDrvRefNum(-2));
- IRState->CDPlayState = 0;
- IRState->CDPauseState = 1;
- }
-
- if (theValue == 2226)
- if (!(IRState->CDPlayState)) {
- Play(1,-2);
- IRState->CDPlayState = 1;
- }
- else
- if (!(IRState->CDPauseState)) {
- APause(IRState->CDPauseState, GetDrvRefNum(-2));
- IRState->CDPauseState = !(IRState->CDPauseState);
- }
-
- if ((theValue >= 2176) && (theValue <= 2184)) {
- Play (theValue - 2175, -2);
- IRState->CDPlayState = 1;
- }
- if ((theValue >= 2208) && (theValue <= 2214)) {
- Play (theValue - 2208 + 10, -2);
- IRState->CDPlayState = 1;
- }
- if ((theValue >= 2192) && (theValue <= 2193)) {
- Play (theValue - 2192 + 17, -2);
- IRState->CDPlayState = 1;
- }
- if (theValue == 2199) {
- Play (19, -2);
- IRState->CDPlayState = 1;
- }
- if (theValue == 2217) {
- Play (20, -2);
- IRState->CDPlayState = 1;
- }
-
- if (theValue == 2233) {
- APause(IRState->CDPauseState, GetDrvRefNum(-2));
- IRState->CDPauseState = !(IRState->CDPauseState);
- }
-
- if (theValue == 2198) {
- AStop(0,GetDrvRefNum(-2));
- IRState->CDPlayState = 0;
- IRState->CDPauseState = 1;
- CDEject(-2);
- }
-
- if (theValue == 2228) {
- if (AScan(0, GetDrvRefNum(-2)) == noErr) {
- IRState->CDScanState = 1;
- }
- }
-
- if (theValue == 2227) {
- if (AScan(1, GetDrvRefNum(-2)) == noErr) {
- IRState->CDScanState = 1;
- }
- }
-
- if ((theValue == 2225) && (IRState->CDPlayState == 1))
- ATrackSkip(1, GetDrvRefNum(-2));
-
- if ((theValue == 2224) && (IRState->CDPlayState == 1))
- ATrackSkip(0, GetDrvRefNum(-2));
-
- DoVideoIR(theValue,IRState);
-
- DoProcessIR(theValue,IRState);
-
- }
- }
-
- void
- DoVideoIR(long theValue,IRStateStruct *IRState) {
-
- switch (theValue) {
- case 144:
- BringToMooVFront(1);
- break;
- case 145:
- BringToMooVFront(0);
- break;
- case 1474:
- if (IsMyWindow(FrontWindow()))
- OffsetWindow(FrontWindow(), 0, -20);
- IRState->oldValue = 0;
- break;
- case 1475:
- if (IsMyWindow(FrontWindow()))
- OffsetWindow(FrontWindow(), 0, 20);
- IRState->oldValue = 0;
- break;
- case 1506:
- if (IsMyWindow(FrontWindow()))
- OffsetWindow(FrontWindow(), -20, 0);
- IRState->oldValue = 0;
- break;
- case 1505:
- if (IsMyWindow(FrontWindow()))
- OffsetWindow(FrontWindow(), 20, 0);
- IRState->oldValue = 0;
- break;
- case 1434: /* VCR Play */
- IRMooVPlay(65536);
- break;
- case 1432: /* VCR Stop */
- IRMooVPlay(0);
- break;
- case 1435: /* VCR Rew */
- IRMooVPlay(-65536 * 2);
- break;
- case 1436: /* VCR FF */
- IRMooVPlay(65536 * 2);
- break;
- case 1448: /* VCR Rew Search */
- IRMooVPlay(-32768);
- break;
- case 1449: /* VCR FF Search */
- IRMooVPlay(32768);
- break;
- case 1533: /* VCR High Speed Rewind */
- IRMooVPlay(-65536 * 20);
- break;
- case 1440: /* VCR Pause in Jog Mode */
- IRMooVPlay(0);
- break;
- case 1457: /* VCR step Forward in Jog Mode */
- IRMooVStep(0);
- IRState->oldValue = 0;
- break;
- case 1456: /* VCR step Back in Jog Mode */
- IRMooVStep(-1);
- IRState->oldValue = 0;
- break;
- case 146: /* Volume ++ */
- IRMooVVolume(1);
- IRState->oldValue = 0;
- break;
- case 147: /* Volume -- */
- IRMooVVolume(0);
- IRState->oldValue = 0;
- break;
- case 149: /* Close Window */
- doCloseCommand();
- break;
- }
- }
-
-
- void
- DoProcessIR(long theValue,IRStateStruct *IRState) {
- ProcessSerialNumber frontProc;
- Boolean equalProc;
- ProcessInfoRec procInfo;
- FSSpec extraFSSpec;
- Str255 extraString;
-
- procInfo.processInfoLength = sizeof(ProcessInfoRec);
- procInfo.processName = extraString;
- procInfo.processAppSpec = &extraFSSpec;
-
- switch (theValue) {
- case 1424:
- IRSwitchLayer(1, IRState);
- break;
- case 1425:
- IRSwitchLayer(0, IRState);
- break;
- case 1429:
- GetFrontProcess(&frontProc);
- SameProcess(&IRState->IRProc, &frontProc, &equalProc);
- if (equalProc)
- quitFlag = 1;
- else {
- if (GetProcessInformation(&frontProc, &procInfo) == noErr ) {
- if (procInfo.processType == 'FNDR') {
- /* ShutDwnPower(); */
- SysBeep(5);
- }
- else {
- QuitAnApp(&frontProc);
- }
- }
- }
- break;
- }
- }
-
- void
- IRSwitchLayer(short forward, IRStateStruct *IRState) {
- ProcessSerialNumber frontProc, currProc, nextProc, prevProc;
- OSErr err;
- Boolean equalProc;
- short foundOne = 0;
- ProcessInfoRec procInfo;
- FSSpec extraFSSpec;
- Str255 extraString;
-
- err = GetFrontProcess(&frontProc);
- if (err != noErr)
- return;
-
- procInfo.processInfoLength = sizeof(ProcessInfoRec);
- procInfo.processName = extraString;
- procInfo.processAppSpec = &extraFSSpec;
-
- currProc.highLongOfPSN = 0;
- currProc.lowLongOfPSN = kNoProcess;
- prevProc.highLongOfPSN = 0;
- prevProc.lowLongOfPSN = kNoProcess;
-
- while ((GetNextProcess(&currProc) == noErr) && (!foundOne)) {
- if (GetProcessInformation(&currProc, &procInfo) == noErr ) {
- if ((!(procInfo.processMode & modeDeskAccessory)) &&
- (!(procInfo.processMode & modeOnlyBackground))) {
-
- SameProcess(&currProc, &frontProc, &equalProc);
- if (equalProc) {
- if (forward) {
- if (GetNextProcess(&currProc) == noErr) {
- nextProc.highLongOfPSN = currProc.highLongOfPSN;
- nextProc.lowLongOfPSN = currProc.lowLongOfPSN;
- foundOne = 1;
- }
- else {
- currProc.highLongOfPSN = 0;
- currProc.lowLongOfPSN = kNoProcess;
- GetNextProcess(&currProc);
- nextProc.highLongOfPSN = currProc.highLongOfPSN;
- nextProc.lowLongOfPSN = currProc.lowLongOfPSN;
- foundOne = 1;
- }
- }
- else {
- if (prevProc.lowLongOfPSN != kNoProcess) {
- nextProc.highLongOfPSN = prevProc.highLongOfPSN;
- nextProc.lowLongOfPSN = prevProc.lowLongOfPSN;
- foundOne = 1;
- }
- else {
- while (GetNextProcess(&currProc) == noErr) {
- nextProc.highLongOfPSN = currProc.highLongOfPSN;
- nextProc.lowLongOfPSN = currProc.lowLongOfPSN;
- }
- foundOne = 1;
- }
- }
- }
- prevProc.highLongOfPSN = currProc.highLongOfPSN;
- prevProc.lowLongOfPSN = currProc.lowLongOfPSN;
- }
- }
- }
-
- if (foundOne)
- SetFrontProcess(&nextProc);
- }
-
- void
- MainEventLoop(void)
- {
- short i;
- char key;
- Boolean track;
- long growResult;
- EventRecord myEvent;
- WindowPtr whichWindow;
- short yieldTime;
- short isEvent;
- IRStateStruct IRState;
- AudioStateStruct aState;
-
- IRState.oldValue = 0;
- IRState.quitFlag = 0;
- IRState.CDPauseState = 1; /* 0 = CD is paused, 1 = CD is playing */
- IRState.CDPlayState = 0;
- IRState.CDScanState = 0;
- GetCurrentProcess(&(IRState.IRProc));
-
- if (!AStatus(GetDrvRefNum(-2), &aState)) {
- switch (aState.aStatusFlags) {
- case 0:
- IRState.CDPlayState = 1;
- break;
- case 1:
- IRState.CDPauseState = 0;
- break;
- }
- }
-
- yieldTime = 0;
- while (!quitFlag) {
-
- isEvent = WaitNextEvent(everyEvent, &myEvent, yieldTime, nil);
-
- ProcessIR(&IRState);
-
- if (playMovies(&myEvent))
- ;
- else
- if (isEvent) {
-
- switch (myEvent.what) {
- case mouseDown:
- switch (FindWindow(myEvent.where, &whichWindow)) {
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
- case inMenuBar:
- doCommand(MenuSelect(myEvent.where));
- break;
- case inContent:
- SelectWindow(whichWindow);
- break;
- case inDrag:
- DragWindow (whichWindow, myEvent.where, &qd.screenBits.bounds);
- break;
- case inGrow:
- break;
- case inGoAway:
- track = TrackGoAway (whichWindow, myEvent.where);
- if (track) doCloseCommand();
- break;
- case inZoomIn:
- break;
- case inZoomOut:
- break;
- default:
- break;
- }
- break;
- case keyDown:
- case autoKey:
- key = myEvent.message & charCodeMask;
- if ( myEvent.modifiers & cmdKey )
- if ( myEvent.what == keyDown )
- doCommand(MenuKey(key));
- break;
- case updateEvt:
- for (i = 0; i < MAXWINDOWS; i++)
- if ((WindowPtr)myEvent.message == myWindow[i]) {
- BeginUpdate((WindowPtr) myWindow[i]);
- EndUpdate((WindowPtr) myWindow[i]);
- }
- break;
- case diskEvt:
- break;
- case activateEvt:
- break;
- case app4Evt:
- break;
- case kHighLevelEvent:
- DoHighLevel(&myEvent);
- break;
- default:
- break;
- }
- }
- }
- }
-
- short
- IsMyWindow(WindowPtr theWindow) {
-
- short i;
-
- for (i = 0; i < MAXWINDOWS; i++)
- if (theWindow == myWindow[i])
- return(1);
-
- return(0);
- }
-
- void
- OffsetWindow(WindowPtr theWindow, short h, short v) {
- Point pt;
- GrafPtr thePort;
-
- GetPort(&thePort);
- SetPort(theWindow);
- pt.h = 0;
- pt.v = 0;
-
- LocalToGlobal(&pt);
- pt.h = pt.h + h;
- pt.v = pt.v + v;
-
- MoveWindow(theWindow, pt.h, pt.v, true);
- SetPort(thePort);
- }
-
- void
- InitAEStuff(void)
- {
-
- AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,(EventHandlerProcPtr) AEOpenHandler,0,false);
- AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,(EventHandlerProcPtr) AEOpenDocHandler,0,false);
- AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,(EventHandlerProcPtr) AEPrintHandler,0,false);
- AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,(EventHandlerProcPtr) AEQuitHandler,0,false);
- }
-
-
-
- void DoHighLevel(EventRecord *AERecord)
- {
-
- AEProcessAppleEvent(AERecord);
-
- }
-
-
- /* This is the standard Open Application event. */
-
- pascal OSErr
- AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- return(noErr);
- }
-
-
- pascal OSErr
- AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- /* we have no docs, so no odoc events should come to us */
-
- return(errAEEventNotHandled);
- }
-
- pascal OSErr
- AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- /* we have no docs, so no pdoc events should come to us */
-
- return(errAEEventNotHandled);
- }
-
-
- pascal OSErr
- AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
-
- quitFlag = 1;
- return(noErr);
- }
-